import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-01-22
 * Time: 21:23
 */
public class Test {
        public int evalRPN(String[] tokens) {
            Stack<Integer> stack = new Stack<>();
            for(String x : tokens) {
                if(!Isoperation(x)) {
                    stack.push(Integer.parseInt(x));
                }else {
                    int num2 = stack.pop();
                    int num1 = stack.pop();
                    switch (x) {
                        case "+":
                            stack.push(num1+num2);
                            break;
                        case "-":
                            stack.push(num1-num2);
                            break;
                        case "*":
                            stack.push(num1*num2);
                            break;
                        case "/":
                            stack.push(num1/num2);
                            break;
                    }
                }
            }
            return stack.pop();
        }
        private boolean Isoperation(String x) {
            if(x.equals("+")||x.equals("-")||x.equals("*")||x.equals("/")) {
                return true;
            }
            return false;
        }

    public static void main(String[] args) {
        Test test = new Test();
        String[] tokens = new String[]{"2","1","+","3","*"};
        System.out.println(test.evalRPN(tokens));
    }
}
